1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 import java.util.EventObject;
34 import java.util.List;
35 import javax.swing.JTable;
36 import javax.swing.table.DefaultTableModel;
37 import javax.swing.table.TableCellEditor;
38 import javax.swing.table.TableCellRenderer;
39 import javax.swing.table.TableColumn;
40
41
42
43
44
45
46 @SuppressWarnings("serial")
47 public class OldJTable extends JTable
48 {
49
50
51
52
53 public int getColumnIndex(Object identifier) {
54 return getColumnModel().getColumnIndex(identifier);
55 }
56
57
58
59
60
61
62 public TableColumn addColumn(Object columnIdentifier, int width) {
63 return addColumn(columnIdentifier, width, null, null, null);
64 }
65
66 public TableColumn addColumn(Object columnIdentifier, List columnData) {
67 return addColumn(columnIdentifier, -1, null, null, columnData);
68 }
69
70
71
72 public TableColumn addColumn(Object columnIdentifier, int width,
73 TableCellRenderer renderer,
74 TableCellEditor editor) {
75 return addColumn(columnIdentifier, width, renderer, editor, null);
76 }
77
78 public TableColumn addColumn(Object columnIdentifier, int width,
79 TableCellRenderer renderer,
80 TableCellEditor editor, List columnData) {
81 checkDefaultTableModel();
82
83
84 DefaultTableModel m = (DefaultTableModel)getModel();
85 m.addColumn(columnIdentifier, columnData.toArray());
86
87
88
89 TableColumn newColumn = new TableColumn(
90 m.getColumnCount()-1, width, renderer, editor);
91 super.addColumn(newColumn);
92 return newColumn;
93 }
94
95
96
97 public void removeColumn(Object columnIdentifier) {
98 super.removeColumn(getColumn(columnIdentifier));
99 }
100
101 public void addRow(Object[] rowData) {
102 checkDefaultTableModel();
103 ((DefaultTableModel)getModel()).addRow(rowData);
104 }
105
106 public void addRow(List rowData) {
107 checkDefaultTableModel();
108 ((DefaultTableModel)getModel()).addRow(rowData.toArray());
109 }
110
111 public void removeRow(int rowIndex) {
112 checkDefaultTableModel();
113 ((DefaultTableModel)getModel()).removeRow(rowIndex);
114 }
115
116 public void moveRow(int startIndex, int endIndex, int toIndex) {
117 checkDefaultTableModel();
118 ((DefaultTableModel)getModel()).moveRow(startIndex, endIndex, toIndex);
119 }
120
121 public void insertRow(int rowIndex, Object[] rowData) {
122 checkDefaultTableModel();
123 ((DefaultTableModel)getModel()).insertRow(rowIndex, rowData);
124 }
125
126 public void insertRow(int rowIndex, List rowData) {
127 checkDefaultTableModel();
128 ((DefaultTableModel)getModel()).insertRow(rowIndex, rowData.toArray());
129 }
130
131 public void setNumRows(int newSize) {
132 checkDefaultTableModel();
133 ((DefaultTableModel)getModel()).setNumRows(newSize);
134 }
135
136 public void setDataVector(Object[][] newData, List columnIds) {
137 checkDefaultTableModel();
138 ((DefaultTableModel)getModel()).setDataVector(
139 newData, columnIds.toArray());
140 }
141
142 public void setDataVector(Object[][] newData, Object[] columnIds) {
143 checkDefaultTableModel();
144 ((DefaultTableModel)getModel()).setDataVector(newData, columnIds);
145 }
146
147 protected void checkDefaultTableModel() {
148 if(!(dataModel instanceof DefaultTableModel))
149 throw new InternalError("In order to use this method, the data model must be an instance of DefaultTableModel.");
150 }
151
152
153
154
155
156 public Object getValueAt(Object columnIdentifier, int rowIndex) {
157 return super.getValueAt(rowIndex, getColumnIndex(columnIdentifier));
158 }
159
160 public boolean isCellEditable(Object columnIdentifier, int rowIndex) {
161 return super.isCellEditable(rowIndex, getColumnIndex(columnIdentifier));
162 }
163
164 public void setValueAt(Object aValue, Object columnIdentifier, int rowIndex) {
165 super.setValueAt(aValue, rowIndex, getColumnIndex(columnIdentifier));
166 }
167
168 public boolean editColumnRow(Object identifier, int row) {
169 return super.editCellAt(row, getColumnIndex(identifier));
170 }
171
172 public void moveColumn(Object columnIdentifier, Object targetColumnIdentifier) {
173 moveColumn(getColumnIndex(columnIdentifier),
174 getColumnIndex(targetColumnIdentifier));
175 }
176
177 public boolean isColumnSelected(Object identifier) {
178 return isColumnSelected(getColumnIndex(identifier));
179 }
180
181 public TableColumn addColumn(int modelColumn, int width) {
182 return addColumn(modelColumn, width, null, null);
183 }
184
185 public TableColumn addColumn(int modelColumn) {
186 return addColumn(modelColumn, 75, null, null);
187 }
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217 public TableColumn addColumn(int modelColumn, int width,
218 TableCellRenderer renderer,
219 TableCellEditor editor) {
220 TableColumn newColumn = new TableColumn(
221 modelColumn, width, renderer, editor);
222 addColumn(newColumn);
223 return newColumn;
224 }
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246 public boolean editColumnRow(int columnIndex, int rowIndex) {
247 return super.editCellAt(rowIndex, columnIndex);
248 }
249
250 public boolean editColumnRow(int columnIndex, int rowIndex, EventObject e){
251 return super.editCellAt(rowIndex, columnIndex, e);
252 }
253
254
255 }